home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
102
/
examples
/
recurse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-01-25
|
1KB
|
43 lines
/*
* run this with 'test1' as the first command line argument. It will
* recurse to three levels if the 'test1, 'test2' and 'test3' files are
* available for it to read. This program works fine with Lattice C
* but fails miserably with the orignial developers kit.
*/
#include "stdio.h"
int main(argc,argv)
int argc;
char **argv;
{
FILE *in;
if (argc > 1) {
if ((in = fopen(argv[1],"r")) == NULL) exit(1);
echofile(in);
fclose(in);
}
exit(0);
}
int echofile(in)
FILE *in;
{
FILE *newin;
char line[BUFSIZ];
while (fgets(line,BUFSIZ,in)) {
printf("%s",line);
if (! strncmp(line,"read ",5)) {
line[strlen(line)-1] = 0;
if ((newin = fopen(line+5,"r")) == NULL) continue;
echofile(newin);
fclose(newin);
}
}
return 0;
}